
package com.xiaopeng.oa.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * 这个问题通常出现在同时引入了WebSocket和Activiti依赖时，因为两者都定义了多个TaskExecutor类型的bean：
 * 4个来自WebSocket配置（clientInboundChannelExecutor、clientOutboundChannelExecutor、brokerChannelExecutor、messageBrokerTaskScheduler）
 * 1个来自Activiti配置（taskExecutor
 */
@Configuration
public class TaskExecutorConfig {

    @Bean
    @Primary
    public TaskExecutor primaryTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5);
        executor.setMaxPoolSize(10);
        executor.setQueueCapacity(25);
        executor.setThreadNamePrefix("primary-");
        executor.initialize();
        return executor;
    }
}
